package cn.smvc.task.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.BasicRowProcessor;
import org.apache.commons.dbutils.BeanProcessor;
import org.apache.commons.dbutils.GenerousBeanProcessor;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.RowProcessor;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.stereotype.Repository;

import cn.smvc.common.dao.JDBCUtils;
import cn.smvc.task.dao.TTimedTaskContactDao;
import cn.smvc.task.entity.TTimedTaskContact;

@Repository
public class TTimedTaskContactDaoImpl implements TTimedTaskContactDao{
	/*
	 * 这两个是处理数据库表字段下划线的，
	 * 		与实体类中的属性对应（驼峰规则）
	 */
	BeanProcessor bean = new GenerousBeanProcessor();
	RowProcessor processor = new BasicRowProcessor(bean);

	@Override
	public List<TTimedTaskContact> getByTaskId(String taskId) throws SQLException {
		QueryRunner queryRunner = new QueryRunner(JDBCUtils.getDataSource());
		StringBuilder sb = new StringBuilder();
		sb.append("select * from t_timed_task_contact where task_id=? ");
		List<TTimedTaskContact> list = null;
		list = queryRunner.query(sb.toString(), 
				new BeanListHandler<TTimedTaskContact>(TTimedTaskContact.class, processor), 
				taskId);
		return list;
	}

}
